package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"go-gin-example/config"
	"go-gin-example/routers"
	"net/http"
)

func init() {
	config.Setup()
}

func main() {
	runMode := config.Global.Server.RunMode
	readTimeout := config.Global.Server.ReadTimeout
	writeTimeout := config.Global.Server.WriteTimeout
	httpPort := config.Global.Server.Port

	gin.SetMode(runMode)

	routersInit := routers.InitRouter()
	endPoint := fmt.Sprintf(":%d", httpPort)
	maxHeaderBytes := 1 << 20

	server := &http.Server{
		Addr:           endPoint,
		Handler:        routersInit,
		ReadTimeout:    readTimeout,
		WriteTimeout:   writeTimeout,
		MaxHeaderBytes: maxHeaderBytes,
	}

	logrus.Infof("start http server listening %s", endPoint)

	err := server.ListenAndServe()
	if err != nil {
		logrus.Fatalf("start http server err, %v", err)
	}
}
